package org.sgx.gwtsjcl.client;

import com.google.gwt.core.client.JavaScriptObject;

public class JSON extends JavaScriptObject{
protected JSON(){}
/**
 * 
 * @return
 */
public native final JavaScriptObject defaults() /*-{
return this["defaults"]; 
}-*/;

/**
 * 
 * @param val
 * @return this - for setter chaining
 */
public native final JSON defaults(JavaScriptObject val) /*-{
this["defaults"] = val; 
return this; 
}-*/;
/**
 * Decode a simple (flat) JSON string into a structure. The ciphertext, adata, salt and iv will be base64-decoded. 
 * @param s the string
 * @return  The decoded structure.
 * @throws  {sjcl.exception.invalid} (Throwable)  if str isn't (simple) JSON.
 */
public native final JavaScriptObject decode(String s) /*-{
return this.decode(s); 
}-*/;
/**
 * Simple decryption function. 
 * @param password The password or key.
 * @param ciphertext The ciphertext to decrypt.
 * @param params Additional non-default parameters.
 * @param rp     A returned object with filled parameters.
@throws (catch(Throwable){}) {sjcl.exception.invalid}   if a parameter is invalid. - 
{sjcl.exception.corrupt}  if the ciphertext is corrupt.
 * @return The plaintext
 */
public native final String decrypt(String password, String ciphertext, 
		EncryptParam params, EncryptParam rp) /*-{
return this.decrypt(password, ciphertext, params, rp); 
}-*/;
/**
 * Simple decryption function. 
 * @param password The password or key.
 * @param ciphertext The ciphertext to decrypt
@throws (catch(Throwable){}) {sjcl.exception.invalid}   if a parameter is invalid. - 
{sjcl.exception.corrupt}  if the ciphertext is corrupt.
 * @return The plaintext
 */
public native final String decrypt(String password, String ciphertext) /*-{
return this.decrypt(password, ciphertext); 
}-*/;

/**
 * Encode a flat structure into a JSON string. 
 * @param obj The structure to encode.
 * @return  A JSON string.
 * @throws  (catch(Throwable){}) {sjcl.exception.invalid} if obj has a non-alphanumeric property. - 
{sjcl.exception.bug} if a parameter has an unsupported type.
 */
public native final String encode(JavaScriptObject obj) /*-{
return this.encode(obj); 
}-*/;
/**
 * 
 * @param password The password or key.
 * @param plaintext The data to encrypt.
 * @param params The parameters including tag, iv and salt.
 * @param rp A returned version with filled-in parameters.
 * @return The ciphertext.
 */
public native final String encrypt(String password, String plaintext, 
		EncryptParam params, EncryptParam rp) /*-{
return this.encrypt(password, plaintext, params, rp); 
}-*/;
/**
 * 
 * @param password The password or key.
 * @param plaintext The data to encrypt.
 * @return The ciphertext.
 */
public native final String encrypt(String password, String plaintext) /*-{
return this.encrypt(password, plaintext); 
}-*/;
}
